<title>OCR使用</title>
<meta charset="UTF-8"/>
<iframe src="index.html"  style="position: absolute;right:0;top:1%;min-height: 300px;border-width: 0px">
</iframe>
<h1>明察秋毫--OCR使用</h1>
<xmp>
        使用OCR，将图片识别为文字,来处理一些验证码，图片小说爬虫等，需要先运行umi-ocr.exe
    语法 OcrDom:需要识别区域的选择器>localStorage的键名
        如:
        $op['js'][]="OcrDom:.captcha img>res";
    在之后的js中可以从 localStorage获取识别结果

        如:
        $op['js'][]=<<<JS
        var capres = localStorage.getItem("res");
<<<JS
</xmp>
<h1>
    示例，使用ocr处理验证码
</h1>
<xmp  style="background:#f0f0f0;white-space: pre;text-align: left" >
    $tmp = explode("-",$item);
    $func ="";
    $url = "https://www.airchinacargo.com/cargo/gzcx/hkyd/list/index_pc.html?waybillPrefix=999&waybillContent=".$tmp[1];
    $header=[];
    $op = [
            "timeout"=>20 , //超时时间
            // "selector"=>"#shipmentnumber-single",//等待css选择器
            "selector"=>"html",//等待css选择器
            "debug"=>0,
            "input"=>'',
            "button"=>'',
            'reuse'=>0,
            'wno'=>$tmp[1]
        ];
    $op['prejs'][]="ListenUrl:awbNumber=999->variableVal";
    //WaitVisible: 等待元素显示
     $op['js'][]="WaitVisible:.captcha img";
     //OcrDom: 识别元素内容
    $op['js'][]="OcrDom:.captcha img>".$tmp[1];

        $op['js'][]=<<<JS
        var capres = localStorage.getItem("$tmp[1]");
        localStorage.removeItem("$tmp[1]");
        capsub =capres.substr(-4)
        console.log(capsub);
        //触发Vue事件
        const event = document.createEvent('HTMLEvents')
        event.initEvent('input', false, true)
        document.getElementsByClassName("captcha-value")[0].value = capsub;
        document.getElementsByClassName("captcha-value")[0].dispatchEvent(event)
        document.getElementsByClassName("captcha-btn")[0].click();
JS;
        $res = HttpClient::RpcChromedpGet($url,$header,$op,$ip,$port,$ua_str,$func);

</xmp>